﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace rndbuddy
{
    public partial class form_signup : Form
    {
        public form_signup()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(inp_email.Text))
            {
                MessageBox.Show("This is not a valid email");
                return;
            }

            string result = server_pipe.apply_for_api_key(inp_email.Text);

            if (result != "true")
            {
                MessageBox.Show(result);
                return;
            }

            //ok was sent
            //activate the controls
            button2.Enabled = true;
            inp_validate.Enabled = true;
			//disable step1
			button1.Enabled = false;
			inp_email.Enabled = false;

            MessageBox.Show("An Email has been sent, containing your Verification Key", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            
            //enable button to get key by whatsapp
            button4.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(inp_validate.Text))
            {
                MessageBox.Show("How about you enter the code you just got? In case you did not get a mail, please double check your spam folder!");
                return;
            }

            string result = server_pipe.validate_email(inp_validate.Text.Trim());
            if (result == "false")
            {
                MessageBox.Show("This Code failed validation");
                return;
            }
			
            //store the api key
            settings.api_key = result;
            settings.storeConfig();
            settings.parseConfig();

            MessageBox.Show("Your Account has been validated. Please restart Honorbuddy!");
            this.Dispose();
            return;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();
            override_key f = new override_key();
            f.ShowDialog();
            this.Dispose();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            validate_by_whatsapp w = new validate_by_whatsapp(inp_email.Text);
            w.ShowDialog();
        }
    }
}
